package m4d1;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

//tcp服务器端
//该类实现服务器套接字
public class dTCPServer {
    public static void main(String[] args) throws IOException {
        //创建绑定特定端口套接字的服务器对象
        ServerSocket serverSocket = new ServerSocket(8888);

        //获取客户端对象
        Socket socket = serverSocket.accept();

        //获取网络字节输入流对象
        InputStream is = socket.getInputStream();

        //使用网络字节输入流的对象，读取客户端发的数据
        byte[] bytes = new byte[1024];
        int len = 0;
        len = is.read(bytes);
        System.out.println(new String(bytes,0,len));

        //获取网络字节输出流对象
        OutputStream os = socket.getOutputStream();

        //给客户点回写信息
        os.write("收到".getBytes());

        socket.close();
        serverSocket.close();

    }
}
